<?php

use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/', function () {
    return view('welcome');
});

Route::get('dologin', 'index\LoginController@dologin');
/*
	Index模块
*/
//$route = null;
Route::group(['prefix' => 'index', 'middleware'=>['web']], function () {

    Route::any('/{controller}/{action}', function ($controller, $action) {
        $request = app('request');
        $controller = 'App\Http\Controllers\index\\'.ucfirst($controller).'Controller';
        $con     = new $controller($request);
        if (preg_match('/^[a-zA-Z][a-zA-Z0-9_]+/is', $action)) {
            if (method_exists($con, $action)) {
                return $con->{$action}($request);
            }
        }
        die('No route found , Please check url parameters');
    });

});

Route::group(['prefix' => 'book', 'middleware'=>['web']], function () {

    Route::any('/{controller}/{action}', function ($controller, $action) {
        $request = app('request');
        $controller = 'App\Http\Controllers\book\\'.ucfirst($controller).'Controller';
        $con     = new $controller($request);
        if (preg_match('/^[a-zA-Z][a-zA-Z0-9_]+/is', $action)) {
            if (method_exists($con, $action)) {
                return $con->{$action}($request);
            }
        }
        die('No route found , Please check url parameters');
    });

});

Route::group(['prefix' => 'admin', 'middleware'=>['web']], function () {

    Route::any('/{controller}/{action}', function ($controller, $action) {
        $request = app('request');
        $controller = 'App\Http\Controllers\admin\\'.ucfirst($controller).'Controller';
        $con     = new $controller($request);
        if (preg_match('/^[a-zA-Z][a-zA-Z0-9_]+/is', $action)) {
            if (method_exists($con, $action)) {
                return $con->{$action}($request);
            }
        }
        die('No route found , Please check url parameters');
    });

});

/*Route::any('/{module}/{class}/{action}', function($module, $class, $action) {
    $ctrl = \App::make("\\App\\Http\\Controllers\\" . $module . "\\" . $class . "Controller");
    return \App::call([$ctrl, $action]);
});*/